/*===== code build by mstore0.1.3 =====*/

/*===== mstoreDev/docs#fixbar:0 =====*/

$$(function($it){
    
    var docType; //文档类型，前端（forClient），后端（forServer）
    var dataType; //数据类型，新添加的（theAdd）

    $it.click({
        toggleDocType: function(){
            $it.selectDocType($(this).data('view'));
        },
        toggleDataType: function(){
            $it.selectDataType($(this).data('param'));
        }
    });
    
    $it.extend({
        domready: function(){
            $it.initSelect();
            $it.selectDocType('forServer');
            $it.scrollToDocItem(location.hash.substr(1));
        },
        initSelect: function(){
            $$.select('#gotoPos', {
                options: docOptions,
                onchange: function(e){
                    $it.scrollToDocItem(e.newValue);
                }
            });
        },
        scrollToDocItem: function(targetId){
            var $target = $('.dataTmpItem[data-item-target="'+ targetId +'"]');
            if(!$target[0]){
                return;
            }
            var top = $target.offset().top - 70;
            $('html, body').animate({scrollTop: top + 'px'}, 500);
        },
        selectDocType: function(newDocType){
            if(newDocType == docType){
                return;
            }
            docType = newDocType;
            var $button = $('#fixbar .filterView span[data-view="'+ docType +'"]');
            $button.addClass('current').siblings().removeClass('current'); 
            var $tbody = $('.paramsBox tbody');
            $tbody.find('tr').show();
            if(docType == "forClient"){
                $tbody.find('.forServer').hide();
            }else{
                $tbody.find('.forClient').hide();
            }
            $it.selectDataType('theAll');
        },
        selectDataType: function(newDataType){
            if(newDataType == dataType){
                return;
            }
            dataType = newDataType;
            var $button = $('#fixbar .filterParams li[data-param="'+ dataType +'"]');
            $button.addClass('current').siblings().removeClass('current'); 
            var $tbody = $('.paramsBox tbody');
            if(dataType == 'theAll'){ //显示所有的数据
                $tbody.find('.' + docType).show();
            }else{ //仅显示对应类型的数据
                $tbody.find('.' + docType).hide();
                $tbody.find('.' + docType + '.' + dataType).show();
            }
        }
    });
    
});    
